# -*- coding: utf-8 -*-

from gluon.fileutils import read_file
try:
	from string import maketrans
except ImportError:
	maketrans = str.maketrans

response.title = T('Quer Perder Quanto?')
response.keywords = T('SIMPA, municipário, municipária, greve, 2016')
response.description = T('Calculadora de perdas salariais para a categoria municipária de Porto Alegre em 2016')

session.forget()
cache_expire = not request.is_local and 300 or 0


# @cache.action(time_expire=300, cache_model=cache.ram, quick='P')
def index():
	form = FORM(
		SELECT(
			OPTION('Limpar resultado', _value='0'),
			OPTION('Calcular sobre mil reais -  R$ 1.000,00', _value='15'),
			OPTION('Padrão 02 - R$ 880,00', _value='4'),
			OPTION('Padrão 03 - R$ 880,00', _value='5'),
			OPTION('Padrão 04 - R$ 880,00', _value='6'),
			OPTION('Padrão 05 - R$ 1.019,90', _value='1'),
			OPTION('Padrão 06 - R$ 1.230,50', _value='2'),
			OPTION('Padrão 07 - R$ 1.476,00', _value='7'),
			OPTION('Padrão NS - R$ 2.066,00', _value='3'),
			OPTION('Padrão M1 - R$ 1.339,30', _value='8'),
			OPTION('Padrão M2 - R$ 1.540,00', _value='9'),
			OPTION('Padrão M3 - R$ 1.804,80', _value='10'),
			OPTION('Padrão M4 - R$ 2.072,00', _value='11'),
			OPTION('Padrão M5 - R$ 2.432,70', _value='12'),
			OPTION('Padrão EM - R$ 1.824,40', _value='13'),
			OPTION('Padrão EX - R$ 2.499,80', _value='14'),
			_name='basico'
		),
		INPUT(_type='submit', _value='OK'),
	)
	return dict(form=form, vars=form.vars)


@cache.action(time_expire=300, cache_model=cache.ram, quick='P')
def what():
	import urllib
	try:
		images = XML(urllib.urlopen('http://www.web2py.com/poweredby/default/images').read())
	except:
		images = []
	return response.render(images=images)


# @cache.action(time_expire=300, cache_model=cache.ram, quick='P')
def download():
	return response.render()


@cache.action(time_expire=300, cache_model=cache.ram, quick='P')
def who():
	return response.render()


@cache.action(time_expire=300, cache_model=cache.ram, quick='P')
def support():
	return response.render()


@cache.action(time_expire=300, cache_model=cache.ram, quick='P')
def documentation():
	return response.render()


@cache.action(time_expire=300, cache_model=cache.ram, quick='P')
def usergroups():
	return response.render()


def contact():
	redirect(URL('default', 'usergroups'))


@cache.action(time_expire=300, cache_model=cache.ram, quick='P')
def videos():
	return response.render()


def security():
	redirect('http://www.web2py.com/book/default/chapter/01#Security')


def api():
	redirect('http://www.web2py.com/book/default/chapter/04#API')


@cache.action(time_expire=300, cache_model=cache.ram, quick='P')
def license():
	import os
	filename = os.path.join(request.env.gluon_parent, 'LICENSE')
	return response.render(dict(license=MARKMIN(read_file(filename))))


def version():
	if request.args(0) == 'raw':
		return request.env.web2py_version
	from gluon.fileutils import parse_version
	(a, b, c, pre_release, build) = parse_version(request.env.web2py_version)
	return 'Version %i.%i.%i (%.4i-%.2i-%.2i %.2i:%.2i:%.2i) %s' % \
		   (a, b, c, build.year, build.month, build.day, build.hour, build.minute, build.second, pre_release)


@cache.action(time_expire=300, cache_model=cache.ram, quick='P')
def examples():
	return response.render()


@cache.action(time_expire=300, cache_model=cache.ram, quick='P')
def changelog():
	import os
	filename = os.path.join(request.env.gluon_parent, 'CHANGELOG')
	return response.render(dict(changelog=MARKMIN(read_file(filename))))
